<template>
	<view class="box-wrapper">
		<view class="top-wrapper" v-show="!hasLogin">
			<view class="login-wrapper" @tap="toLogin">
				<image src="../../static/tabs/默认头像.jpg">
				</image>
				<text style="">立即登录</text>

			</view>
			<view style="margin-right: 24upx;margin-top: 100upx;display: flex;flex-direction: row;align-items: center;" >
				<text style="color: gray;" >
					主页
				</text>
				<image src="../../static/images/right-icon.png" style="width: 40upx;height: 40upx;"></image>

			</view>
		</view>


		<view class="top-wrapper" v-show="hasLogin">
			<view class="login-wrapper" click="toLogin">
				<image :src="userInfo.headPortrait">
				</image>
				<text style="">{{userInfo.account}}</text>
			</view>
			<view style="margin-right: 24upx;margin-top: 100upx;display: flex;flex-direction: row;align-items: center;">
				<text style="color: gray;" @click="toUserInfo">
					主页
				</text>
				<image src="../../static/images/right-icon.png" style="width: 40upx;height: 40upx;"></image>

			</view>
		</view>

		<view
			style="display: flex;flex-direction: row;justify-content: space-between;background-color: #ffffff;margin:20upx;height: 100upx;border-radius: 20upx;align-items: center;">
			<text style="font-weight: bold;margin-left: 12upx;">浏览历史</text>
			<view style="display: flex;flex-direction: row;align-items: center;" @click="toUserBrowse">
				<text style="color: gray;">
					更多
				</text>
				<image src="../../static/images/right-icon.png" style="width: 40upx;height: 40upx;margin-right: 12upx;">
				</image>
			</view>
		</view>
		
		<view style="display: flex;flex-direction: row;align-items: center;margin-left: 24upx;">
			<image v-for="item in browseList" class="browse-image" :src="item" mode="aspectFill"></image>
		</view>



		<view
			style="display: flex;flex-direction: column;justify-content: space-between;background-color: #ffffff;margin:20upx;height: 260upx;border-radius: 20upx;align-items: flex-start;">
			<text style="font-weight: bold;margin-left: 12upx;margin-top: 12upx;margin-left: 12upx;">常用功能</text>
			<view
				style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;width: 100%;">

				<view class="common-item" @click="toCollect">
					<image src="../../static/images/collect.png"></image>
					<text>我的收藏</text>
				</view>

				<view class="common-item" @click="toChefVerify">
					<image src="../../static/images/auth.png"></image>
					<text>厨师认证</text>
				</view>
				<view class="common-item" @click="toApponitList">
					<image src="../../static/images/customer.png"></image>
					<text>预约订单</text>
				</view>
				<view class="common-item" @click="toUserInfo">
					<image src="../../static/images/settings.png" style=""></image>
					<text>我的设置</text>
				</view>
			</view>
		</view>


		<view>

		</view>

	</view>
</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'

	import {
		user_info
	} from '../../api/auth.js'

	import {
		browse_record
	} from '../../api/user.js'

	export default {

		data() {
			return {
				hasLogin: false,
				userInfo: {},
				browseList: [],
				severList: [
					[{
							name: '我的收藏',
							icon: 'point.png',
							url: '/pages/collect/collect'
						},

					],
					[{
							name: '随机选菜',
							icon: 'choujiang.png',
							url: '/pages/lottery/lottery'
						},
						{
							name: '服务与隐私',
							icon: 'addr.png'
						},
						{
							name: '反馈与建议',
							icon: 'kefu.png'
						}
					]
				],
			};
		},
		onLoad() {
			//加载
			// this.init();
			this.getUserInfo();
			this.getUserBrowseRecord()
		},
		onShow() {
			this.getUserInfo();
			this.getUserBrowseRecord()
		},
		methods: {
			toChefVerify(){
				uni.navigateTo({
					url: '../chefVerify/chefVerify',
				});
			},
			toApponitList(){
				uni.navigateTo({
					url: '../appointment/appointment',
				});
			},
			toUserInfo(){
				uni.navigateTo({
					url: '../userInfo/userInfo',
				});
			},
			
			toUserBrowse(){
				uni.navigateTo({
					url: '../browseList/browseList',
				});
			},
			toCollect() {
				uni.navigateTo({
					url: '../collect/collect',
				});
			},
			toLogin() {
				uni.navigateTo({
					url: '../login/login',
				});
			},
			getUserInfo() {
				user_info().then(res => {
					if (res.code === '200') {
						this.userInfo = res.data
						this.hasLogin = true
					}
				})
			},
			getUserBrowseRecord() {
				browse_record({}).then(res => {
					this.browseImageList = res.data.map(item => {
						return item.picture
					})
					this.browseList = this.browseImageList.slice(0, 4)
				})
			},

			bindLogout() {
				this.logout();
				if (this.forcedLogin) {
					uni.reLaunch({
						url: '../login/login',
					});
				}
			},
			//用户点击订单类型
			toOrderType(index) {
				uni.showToast({
					title: this.orderTypeLise[index].name
				});
			},
			//用户点击列表项
			toPage(list_i, li_i) {
				uni.showToast({
						title: this.severList[list_i][li_i].name
					}),
					uni.navigateTo({
						url: this.severList[list_i][li_i].url
					})
			}
		}
	}
</script>

<style lang="scss">
	.box-wrapper {
		background-color: #f4f4f4;
		height: 100vh;
	}

	.browse-image{
		border-radius: 24upx;
		margin-left: 12upx;
		width: 150upx;
		height: 150upx;
	}
	.top-wrapper {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		height: 300upx;
		background: linear-gradient(to bottom, #E9A06F, #e8e4ab);
	}

	.login-wrapper {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 24upx;
		margin-top: 100upx;

		image {
			width: 140upx;
			height: 140upx;
			border-radius: 70upx;
		}

		text {
			font-size: 48upx;
			font-weight: bold;
			margin-left: 16upx;
		}
	}

	.common-item {
		display: flex;
		flex-direction: column;
		align-items: center;

		image {
			width: 60upx;
			height: 60upx;
			margin-right: 12upx;
			margin-left: 24upx;
		}

		text {
			margin-top: 12upx;
			font-size: 26upx;
			margin-bottom: 12upx;
		}
	}
</style>